package jtech.math;



public class Math2 {

	public static float random(int min, int max) {
		return (float) (min + (Math.random() * (max - min)));
	}
	
	public static float decay(float value, float minus) {
		return (value <= 0) ? 0f : (value - minus > 0f ? value - minus : 0f);
	}
	
	public static float randomRadians() {
    	return (float) Math.toRadians(Math.random() * 360);
    }
	
	public static Vec2f toLocalPoint(Vec2f position, Vec2f heading, Vec2f globalPoint) {
		Vec2f side = Vec2f.perpendicular(heading);
		float newX = heading.x * globalPoint.x + heading.y * globalPoint.y + (-position.dot( heading ));
		float newY = side.x    * globalPoint.x + side.y    * globalPoint.y + (-position.dot( side ));
		return new Vec2f(newX, newY);
	}

	public static Vec2f toLocalVector(Vec2f position, Vec2f heading, Vec2f globalVector) {
		Vec2f side = Vec2f.perpendicular(heading);
		float newX = heading.x * globalVector.x + heading.y * globalVector.y;
		float newY = side.x    * globalVector.x + side.y    * globalVector.y;
		return new Vec2f(newX, newY);
	}
	
	public static Vec2f toGlobalPoint(Vec2f position, Vec2f heading, Vec2f localPoint) {
		Vec2f side = Vec2f.perpendicular(heading);
		float newX = heading.x * localPoint.x + side.x * localPoint.y + position.x;
		float newY = heading.y * localPoint.x + side.y * localPoint.y + position.y;
		return new Vec2f(newX, newY);
	}
	
	public static Vec2f toGlobalVector(Vec2f position, Vec2f heading, Vec2f localVector) {
		Vec2f side = Vec2f.perpendicular(heading);
		float newX = heading.x * localVector.x + side.x * localVector.y;
		float newY = heading.y * localVector.x + side.y * localVector.y;
		return new Vec2f(newX, newY);
	}
	
}
